package com.ruoyi.web.member.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.member.domain.FamilyMap;
import com.ruoyi.member.service.IFamilyMapService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家庭成员和家庭关联中间Controller
 * 
 * @author ruoyi
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/member/map")
public class FamilyMapController extends BaseController
{
    @Autowired
    private IFamilyMapService familyMapService;

    /**
     * 查询家庭成员和家庭关联中间列表
     */
    @PreAuthorize("@ss.hasPermi('member:map:list')")
    @GetMapping("/list")
    public TableDataInfo list(FamilyMap familyMap)
    {
        startPage();
        List<FamilyMap> list = familyMapService.selectFamilyMapList(familyMap);
        return getDataTable(list);
    }

    /**
     * 导出家庭成员和家庭关联中间列表
     */
    @PreAuthorize("@ss.hasPermi('member:map:export')")
    @Log(title = "家庭成员和家庭关联中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FamilyMap familyMap)
    {
        List<FamilyMap> list = familyMapService.selectFamilyMapList(familyMap);
        ExcelUtil<FamilyMap> util = new ExcelUtil<FamilyMap>(FamilyMap.class);
        util.exportExcel(response, list, "家庭成员和家庭关联中间数据");
    }

    /**
     * 获取家庭成员和家庭关联中间详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:map:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(familyMapService.selectFamilyMapById(id));
    }

    /**
     * 新增家庭成员和家庭关联中间
     */
    @PreAuthorize("@ss.hasPermi('member:map:add')")
    @Log(title = "家庭成员和家庭关联中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyMap familyMap)
    {
        return toAjax(familyMapService.insertFamilyMap(familyMap));
    }

    /**
     * 修改家庭成员和家庭关联中间
     */
    @PreAuthorize("@ss.hasPermi('member:map:edit')")
    @Log(title = "家庭成员和家庭关联中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyMap familyMap)
    {
        return toAjax(familyMapService.updateFamilyMap(familyMap));
    }

    /**
     * 删除家庭成员和家庭关联中间
     */
    @PreAuthorize("@ss.hasPermi('member:map:remove')")
    @Log(title = "家庭成员和家庭关联中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(familyMapService.deleteFamilyMapByIds(ids));
    }
}
